<?php
//----------------------------------------------------------------------------------------------------------
    require_once('../config.inc.php');

    require_once($config['app_dir'] . '/classes/stockplot.view.php');
    require_once($config['app_dir'] . '/classes/stockplot.data.php');
    //------------------------------------------------------------------------------------------------------
    try {
        //---------------------------------------------------------------------------------------------------
        // checking input parameters
        //---------------------------------------------------------------------------------------------------
        $StockParams = new objStockParams();
        //---------------------------------------------------------------------------------------------------
        // preparing data for graph
        //---------------------------------------------------------------------------------------------------
        $show_days = $config['show']['max_days'];//21;
        $min_show_days = $config['show']['min_days'];//17;

        $now = getdate(mktime());
        $finish = mktime(0,0,0, $now['mon'], $now['mday'], $now['year']);
    	$start = mktime(0,0,0,1,1,2006);

        if(adodb_date2('U', $StockParams->start) < $start || adodb_date2('U', $StockParams->finish) > $finish)
            return; //image error

        $cashe_time = 5*364*60*24; // caching

//        $StockView = new objStockView(635, 390, $cashe_time); //caching
        $StockView = new objStockView(800, 500, $cashe_time); //caching

       //---------------------------------------------------------------------------------------------------
        if( !$StockView->is_cached ) {
            $StockModel = new objStockModel($StockParams->trade, $StockParams->start, $StockParams->finish);
            $StockModel->StrongInterval(true);
            $StockModel->ExactInterval(false);
            $StockModel->SetSystemID($StockParams->system);
            //------------------------------------------------------------------------------------------------
            // generating graph
            //------------------------------------------------------------------------------------------------
            $StockView->HideLogo();
            $StockView->HideCopyright();
            $StockView->HideNews();
            $StockView->SelectWeekends(false);
            $StockView->DivideWeeks(true);
            $StockView->SetDisabledVectorColors(array(3));
   //          $StockView->SetVectorColors(array('darkgreen', 'darkgreen', 'orange', 'red'));
            $StockView->setLegendTitles(array('darkgreen'=>'correct forecast', 'red'=>'incorrect forecast'));
            $StockView->SetData($StockModel->getData());

            $StockView->Render(); //view picture
        } //if not cached
        //---------------------------------------------------------------------------------------------------
    } catch (Exception $e) {
        echo 'Error: ',  $e->getMessage(), "\n";
    }
   //-------------------------------------------------------------------------------------------------------
?>
